home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Information / WebSites / Wirenet / files / Dashboard2.lha / Dashboard2 / AmiTCP / bin / WirenetPrefs < prev   
Text File  |  1998-04-23  |  5KB  |  172 lines

  1. /*
  2. $VER: WirenetPrefs 2.0 (17.4.98)
  3. (c) Neil Bothwick
  4.  
  5. Manages Wirenet preferences settings
  6. */
  7.  
  8. options results
  9. address command
  10.  
  11. /* ;;; Initialise */
  12. Usage = 'Usage: WirenetPrefs Load|Save|Use|Show|Flush|Copy|Convert'
  13. PrefsFile = 'ENV:Wirenet.prefs'
  14. PrefNames = 'WWW FTP ButtonA ButtonB NodeName DomainName UserName MailBox IPAddress Password'
  15. PrefNames = PrefNames 'DialWindow Gateway ModemDev ModemDial ModemInit ModemSpeed MTU PopNum'
  16. PrefNames = PrefNames 'PPPoptions UsePAP TCPstack MailServer NewsServer SMTPServer'
  17. PrefNames = PrefNames 'AminetServer DownloadDir AminetRoot GetReadme NewsSockets MaxTries'
  18. lf = '0a'x
  19. ;;;
  20. /* ;;; Select option */
  21. parse arg args
  22. args = upper(args)
  23. select
  24.     when args = 'LOAD'    then call LoadPrefs()
  25.     when args = 'USE'     then call UsePrefs()
  26.     when args = 'SAVE'    then call SavePrefs()
  27.     when args = 'SHOW'    then call ShowPrefs()
  28.     when args = 'COPY'    then call CopyPrefs()
  29.     when args = 'FLUSH'   then call FlushPrefs()
  30.     when args = 'CONVERT' then call ConvPrefs()
  31.     otherwise ExitMsg(Usage)
  32.     end
  33. exit
  34. ;;;
  35. /* ;;; Exit with message */
  36. ExitMsg:
  37.     parse arg msg
  38.     call rtezrequest(msg,' OK ','Wirenet Prefs','rt_reqpos = reqpos_centerscr')
  39.     exit
  40.     return
  41. ;;;
  42. /* ;;; Load preferences */
  43. LoadPrefs:
  44.     call FlushPrefs()
  45.     Names = ''
  46.     Values = ''
  47.     if ~open(prefs,PrefsFile,'R') then call ExitMsg('Failed to read preferences file')
  48.     do until eof(prefs)
  49.         line = readln(prefs)
  50.         if line = '' then iterate
  51.         if pos(left(line,1),';#') > 0 then iterate
  52.         parse var line name ':' value
  53.         value = strip(value)
  54.         call setclip(name,value)
  55.         end
  56.     call setclip('HostName',getclip('NodeName')||getclip('DomainName'))
  57.     call setclip('WirenetPrefs','TRUE')
  58.     'setenv IPADDRESS' getclip('IPAddress')
  59.     'setenv NODENAME' getclip('NodeName')
  60.     'setenv DOMAINNAME' getclip('DomainName')
  61.     'setenv HOSTNAME' getclip('HostName')
  62.     'setenv HOST' getclip('NodeName')||getclip('DomainName')
  63.     'setenv USERNAME' getclip('UserName')
  64.     'setenv USER' getclip('UserName')
  65.     return
  66. ;;;
  67. /* ;;; Use Preferences */
  68. UsePrefs:
  69.     if ~open(prefs,PrefsFile,'W') then call ExitMsg('Failed to save preferences')
  70.     call writeln(prefs,'# Wirenet preferences file')
  71.     do i = 1 to words(PrefNames)
  72.         name =word(PrefNames,i)
  73.         call writeln(prefs,name':' getclip(name))
  74.         end
  75.     call close(prefs)
  76.     return
  77. ;;;
  78. /* ;;; Save Preferences */
  79. SavePrefs:
  80.     call UsePrefs()
  81.     'copy >NIL:' PrefsFile 'ENVARC:'
  82.     return
  83. ;;;
  84. /* ;;; Show Preferences */
  85. ShowPrefs:
  86.     do i = 1 to words(PrefNames)
  87.         name =word(PrefNames,i)
  88.         say left(name':             ',20)'"'getclip(name)'"'
  89.         end
  90.     return
  91. ;;;
  92. /* ;;; Copy preferences to Dashboard */
  93. CopyPrefs:
  94.     if getclip('WirenetPrefs') ~= 'TRUE' then call LoadPrefs()
  95.     /* Make sure Gui4Cli is running */
  96.     if show('P','Gui4Cli') = 0 then do
  97.         call ExitMsg('Dashboard must be running'lf'to use the Copy option')
  98.         exit
  99.         end
  100.     address 'Gui4Cli'
  101.  
  102.     'DelVar Dashboard/PrefsRead'
  103.     Values = ''
  104.     Names = ''
  105.     do i = 1 to words(PrefNames)
  106.         'SetVar Dashboard/'word(PrefNames,i) '"'getclip(word(PrefNames,i))'"'
  107.         end
  108.     'SetVar Dashboard/PrefsRead 1'
  109.     return
  110. ;;;
  111. /* ;;; Flush preferences */
  112. FlushPrefs:
  113.     do i = 1 to words(PrefNames)
  114.         call setclip(word(PrefNames,i))
  115.         end
  116.     return
  117. ;;;
  118. /* ;;; Convert preferences*/
  119. /* Converts old env var based preferences */
  120. ConvPrefs:
  121.     if exists(PrefsFile) then do
  122.         'copy >NIL:' PrefsFile PrefsFile'.bak clone'
  123.         'copy >NIL:' PrefsFile'.bak ENVARC: clone'
  124.         end
  125.  
  126.     call FetchVar('NodeName','NODENAME')
  127.     call FetchVar('DomainName','DOMAINNAME')
  128.     call FetchVar('UserName','USERNAME')
  129.     call FetchVar('MailBox','MAILBOX')
  130.     call FetchVar('IPAddress','IPADDRESS')
  131.     call FetchVar('DialWindow','Wirenet/DialWindow')
  132.     call FetchVar('Gateway','Wirenet/Gateway')
  133.     call FetchVar('ModemDev','Wirenet/ModemDev')
  134.     call FetchVar('ModemDial','Wirenet/ModemDial')
  135.     call FetchVar('ModemInit','Wirenet/ModemInit')
  136.     call FetchVar('ModemSpeed','Wirenet/ModemSpeed')
  137.     call FetchVar('MTU','Wirenet/MTU')
  138.     call FetchVar('PopNum','Wirenet/PopNum')
  139.     call FetchVar('PPPoptions','Wirenet/ppp.options')
  140.     call FetchVar('MailServer','MAILSERVER')
  141.     call FetchVar('NewsServer','NEWSSERVER')
  142.     call FetchVar('SMTPServer','SMTPSERVER')
  143.     call FetchVar('AminetServer','FTPSERVER')
  144.     call FetchVar('DownloadDir','FTPDIR')
  145.     call FetchVar('AminetRoot','FTPROOT')
  146.     if exists('ENVARC:Wirenet/pap.config') then call setclip('Password',word(GetVar('ENVARC:Wirenet/pap.config'),2))
  147.     call setclip('UsePAP',exists('ENV:Wirenet/UsePAP'))
  148.     call setclip('TCPstack',exists('ENV:Wirenet/UseMiami'))
  149.     call setclip('GetReadme',exists('ENV:FTPREADME'))
  150.     call setclip('NewsSockets',3)
  151.     call setclip('MaxTries',5)
  152.     call setclip('WWW','AWeb3:Aweb')
  153.     call setclip('FTP','Wirenet:AmiFTP')
  154.     call setclip('ButtonA','User A')
  155.     call setclip('ButtonB','User B')
  156.  
  157.     call  SavePrefs()
  158.  
  159.     return
  160.  
  161. /* Reads environment variable into clip, with default */
  162. FetchVar:
  163.     clip = arg(1)
  164.     env = arg(2)
  165.     def = arg(3)
  166.  
  167.     if exists('ENV:'env) then val = GetVar(env)
  168.     else val = def
  169.     call setclip(clip,val)
  170.     return
  171. ;;;
  172.